package org.nch.videoLauncher.presenter;

import org.nch.videoLauncher.view.IHistoryView;
import org.nch.videoLauncher.domain.PlaybackEvent;
import org.nch.videoLauncher.domain.VideoItem;
import org.nch.videoLauncher.task.VideoItemTask;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: bill
 * Date: Jan 8, 2009
 * Time: 1:00:40 PM
 * To change this template use File | Settings | File Templates.
 */
public class HistoryPresenter {

    private IHistoryView view;
    private List<PlaybackEvent> playbackEvents;
    private MainWindowPresenter mainWindowPresenter;
    private Integer currentVideoItemIndex;
    private VideoItem currentVideoItem;
    private VideoItemTask task;

    public HistoryPresenter(IHistoryView hv, MainWindowPresenter mwPresenter){

        this.view = hv;
        this.mainWindowPresenter = mwPresenter;
        task = new VideoItemTask();
        this.playbackEvents = task.getAllHistory();
        view.setPlaybackEvents(playbackEvents);
        mainWindowPresenter.setMainWindowMessageText("Playback history sorted from most recent.  Select a video to play.");
        
    }

    public void selectionChanged(Integer index){
        this.currentVideoItemIndex = index;
        view.setPlayButtonEnabled(true);
    }

    public void playRequested(){
        this.currentVideoItem = playbackEvents.get(currentVideoItemIndex).getVideoItem();
        task.playVideoItem(currentVideoItem);
        this.playbackEvents = task.getAllHistory();
        view.setPlaybackEvents(playbackEvents);

    }

}
